import View from 'ol/View'
import Map from 'ol/Map'
import { register } from 'ol/proj/proj4';
import proj4 from 'proj4';
import { transform, useGeographic, Projection, addProjection } from "ol/proj";
import { get as getProjection } from "ol/proj";
import { boundingExtent } from 'ol/extent'
/**
 * @description: 地图初始化
 * @param {String} containerId 容器id，必传
 * @param {Array} centerCoor 中心点坐标（数组形式）
 * @param {Number} zoom 地图初始的缩放级别，非必传，默认0级
 * @param {String} proj 地图坐标系，非必传，默认为EPSG:4326
 * @param {Number} minZoom 地图可缩放的最小级数，非必传，默认0级
 * @param {Number} maxZoom 地图可缩放的最大级数，非必传，默认19级
 * @return {*} 创建好的地图对象
 */
function init(containerId, centerCoor, zoom, proj, minZoom, maxZoom) {
    //自定义坐标系
    // const projection = getProjection("szbj54");
    const projection = getProjection("sz2000");
    const view = new View({
        center: centerCoor || [0, 0],
        // projection: "EPSG:3857",
        projection: projection,
        zoom: zoom || 0,
        minZoom: minZoom || 0,
        maxZoom: maxZoom || 25,
        extent: [ 
            151922.0542122473, 567150.186555957, 559367.3378574322, 762172.173884043],
        // smoothExtentConstraint : true,
        // constrainResolution : true
    });

    //创建地图
    const map = new Map({
        target: containerId,
        view: view,
        controls: []
    });
    return map;
}
export default {
    init,
}